#include "DepthTexture.h"

DepthTexture::DepthTexture(int width, int height)
{
	glGenTextures(1, &id);
	glBindTexture(GL_TEXTURE_2D, id);

	DWORD err = 0;
	err = glGetError();
	//glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
	//glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	err = glGetError();

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
	err = glGetError();

	glBindTexture(GL_TEXTURE_2D, 0);
}

DepthTexture::~DepthTexture()
{
	if (id != NULL)
		glDeleteTextures(1, &id);
}

void DepthTexture::BindTexture()
{
	glBindTexture(GL_TEXTURE_2D, id);
}

UINT DepthTexture::GetId()
{
	return id;
}